/**
 * @author		Ben Layet
 * @version 	1.0
 * @date		25 Sep 2008
 */
package org.ignoramus.application.model;

import org.ignoramus.application.model.AnswerCheckers.AnswerChecker;

/**
 * An element of the card.
 */
public class CardElement
{
	/** The type of field for the question. */
	private final QuestionMode questionFieldType;
	/** The answer checker. */
	private final AnswerChecker checker;
	/** The name of the element. */
	private final String name;
	/** The value of the element. Can be null*/
	private String value;
	
	/**
	 * Sole constructor.
	 * 
	 * @param templateElmt The card template element.
	 * @param value The value of the element. (Can be null)
	 */
	public CardElement(CardTemplateElement templateElmt, String value)
	{
		this.checker = templateElmt.getChecker();
		this.name = templateElmt.getName();
		this.questionFieldType =  templateElmt.getQuestionFieldType();
		this.value = value;
	}
	/**
	 * @return The type of field for the question.
	 */
	public QuestionMode getQuestionFieldType()
	{
		return questionFieldType;
	}
	/**
	 * @param value the value to set (Can be null)
	 */
	public void setValue(String value)
	{
		this.value = value;
	}
	/**
	 * @return the information value. (Can be null)
	 */
	public String getValue()
	{
		return value;
	}
	
	/**
	 * @return the name
	 */
	public String getName()
	{
		return name;
	}
	
	/**
	 * Check if the element contains information.
	 * @return true the element contains information.
	 */
	public boolean hasInformation()
	{
		return value != null;
	}
	
	/**
	 * @return true if the answer is correct.
	 */
	public boolean checkAnswer(String submittedAnswer)
	{
		return checker.isCorrect(value, submittedAnswer);
	}
}
